Ccay.Module.define("Ccay.task.Export2", function(page, $S) {
			/**
			 * Grid初始化
			 */
			page.ready = function() {
				$("#ccay-operate").ccayToolbar({
							items : [{
								type : "imgBtn",
								icon : "search",
								text : "ccay.common.button.search",
								css : "default", // 回车搜索的按钮的class
								attr : {
									id : "btnSearch"
								}
							}, {
								type : "imgBtn",
								icon : "reset",
								text : "ccay.common.button.reset",
								css : "reset",
								attr : {
									id : "reset"
								}
							}]
						});
				$("#ccay-grid-toolbar").ccayToolbar({
							items : [{
								type : "imgBtn",
								icon : "del",
								text : "ccay.common.button.delete",
								click : Ccay.task.Export2.del,
								attr : {
									id : "del"
								}
							}]
						});
				
				// totalTime渲染器参数设置
				var showUnit = {
					// getFormat初始化时，返回设置页面显示格式，如：2s
					getFormat: function (field, format){
						return "${totalTime}" + "s";
					}
				}
				var gridOptions = {
					//height : 300,
					percentWidth : true,
					wrap : true,
					showSwitch:true,
					allowFilter: true,
					switchMode:"search",
					genSearchByFilter:true,
					// 设置igrid缓存数据
					cacheData : true,
					// 设置缓存key值
					//cacheKey : ["taskId"],
					storageOp:{
						// 设置igrid缓存数据
					    cache: true,
						// 设置缓存key值
					    cacheKey:["taskId"]
					},
					// 分组显示
					//update 2014.1.1 hufeng 00214522 添加开关
					rowRender : Ccay.UI.Config.excel.rowRender,
					//end update
					rowRenderOp : {
						simpleSort : true,
						spareFields : ["exportDate", "moduleName", "exportFlag"]
					},
					pagerOp : {
						anchorPanel : "#taskExportGrid"
					},
					showToolBar: true,
					customSetting: true,
					toolPanel: "#ccay-grid-toolbar",
					// 列设置
					columns : [{
						width : "5%",
						columnType : 'select',
						multi : true,
						freezeable : true
					}, {
						field : 'tmpName',
						header : "ccay.async.label.taskExportFileName",
						cssName : "left",
						width : "12%",
						filter: true,
						content : "${#tmpNamedownLoadRenderer(data)}"
					},
					{
						field : 'moduleName',
						header : "ccay.async.label.taskExportCatalogName",
						cssName : "left",
						filter: {enumable: true,ajax:{url:"services/ccay/task/export/list"},valueField:"moduleName"},
						width : "10%"
					}, {
						field : 'exportFlag',
						header : "ccay.async.label.taskExportStatus",
						cssName : "center",
						content : "${#exportFlagRenderer(data)}",
						width : "5%",
						filter:{input:false,defaultFilters: false,defines:[{value : "0", text:"ccay.common.message.waiting"},{value : "1", text:"ccay.common.message.inProcess"},{value : "2", text:"ccay.common.message.succeed"},{value : "3", text:"ccay.common.message.failed"},{value : "4", text:"ccay.common.message.syncFailed"}]},
						getGroupValue : function(value, record) { // 渲染分组操作的组名
							if (value == "0") {
								return $i18n("ccay.common.message.waiting");
							} else if (value == "1") {
								return $i18n("ccay.common.message.inProcess");
							} else if (value == "2") {
								return $i18n("ccay.common.message.succeed");
							} else if (value == "3") {
								return $i18n("ccay.common.message.failed");
							} else if (value == "4") {
								return $i18n("ccay.common.message.syncFailed");
							}
							return "";
						}
					}, {
						field : 'fileSize',
						hidden : true,
						header : "ccay.async.label.taskExportFileSize",
						cssName : "right",
						width : "5%",
						content : "${#fileSizeRender(data)}"
					}, {
						field : 'records',
						hidden : true,
						header : "ccay.async.label.taskExportRecords",
						type : "integer",
						filter: true,
						cssName : "right",
						width : "5%"
					}, {
						field : 'totalTime',
						hidden : true,
						header : "ccay.task.label.importConsumeTime",
						type : "integer",
						renderer: Ccay.UI.Renderer.create(showUnit),
						cssName : "right",
						width : "8%"
					}, {
						field : 'exportDate',
						width : "10%",
						type: 'date',
						filter: {range:true},
						group : true,
						header : "ccay.task.label.importCreatedTime",
						cssName : "center",
						content : "${#thisToDateBefore(data.exportDate)}",
						getGroupValue : function(value, record) {// 渲染分组操作的组名
							return value.toDate().getUTCTime().format();
						}
					}, {
						field : 'runStartTime',
						hidden : true,
						width : "10%",
						type: 'date',
						filter: {range:true},
						header : "ccay.task.label.importRunStartTime",
						cssName : "center",
						content : "${#thisToDateBefore(data.runStartTime)}"
					}],
					// 设置igrid的ajax请求参数，url属性获取数据源的链接地址
					ajax : {
						url : 'services/ccay/task/export/list/page/${pageSize}/${curPage}/${filter}'
					},
					// Grid操作设置
					operation : {
						search : {
							// 查询按钮id选择器
							//btn : '#btnSearch',
							// 查询条件区域id选择器
							panel : '#searchForm'
							// 查询请求地址
							//url : 'services/ccay/task/export/list/page/{0}/{1}'
						}
					}
				}
				// 初始化Grid
				$S("#taskExportGrid").igrid(gridOptions);
			};

			/** grid删除按钮 */
			page.del = function() {
				var grid = "#taskExportGrid";
				var records = $(grid).manager().getSelectedRecords();
				var url = "services/ccay/task/export/d/list";
				if (records.length > 0) {
					Ccay.UI.confirm("ccay.common.message.confdel", function(result) {
								if (result) {
									Ccay.doPut(url, records, function() {
												Ccay.UI.topBox("ccay.common.message.success");
												// 调用刷新grid的方法
												$(grid).manager().reload(true, true, true);												
											});
								}
							});
				} else {
					//Ccay.UI.showMessage("ccay.common.message.selectedRecords", "warn");
					Ccay.UI.topBox({content:"ccay.common.message.selectedRecords",style:"warn"});
				}

			};
			

			page.listExportFlag = function() {
				return [{
					value : 0,
					text : $i18n("ccay.common.message.waiting")
				}, {
					value : 1,
					text : $i18n("ccay.common.message.inProcess")
				}, {
					value : 2,
					text : $i18n("ccay.common.message.succeed")
				}, {
					value : 3,
					text : $i18n("ccay.common.message.failed")
				}];
			};

			fileSizeRender = function(data) {
				var fSize = data.fileSize;
				if (!fSize)
					return "";
				return Ccay.Format.toFileSize(fSize);
			};

			// 对时间进行格式化处理
			thisToDateBefore = function(data) {
				return Ccay.Format.toDateBefore(data && data.getUTCTime());
			};

			/**
			 * 用户id
			 */
			function userId2Account(value, record, columnObj, grid, colNo, rowNo) {
				return "<a title={0} class='init PersonInfo' id='userAccount'  scope='intranet'>{1}</a>".formatValue(value, value);
			};

			// 设置任务状态 (0:Pending ,1:Run , 2:Finish ,3:Restart,4: Failed )
			exportFlagRenderer = function(record) {
				var dis = "";
				var value = record.exportFlag;
				if (value == "0") {
					dis = $i18n("ccay.common.message.waiting");
				} else if (value == "1") {
					dis = $i18n("ccay.common.message.inProcess");
				} else if (value == "2") {
					var succeedShow = $i18n("ccay.common.message.succeed");
					var succeedSize = "";
					if (record.fileSize) {
						succeedSize = Ccay.Format.toFileSize(record.fileSize);
					}
					var succeedTitle = $i18n("ccay.async.label.taskExportFileSize") + ":" + succeedSize + "\n" + $i18n("ccay.async.label.taskExportRecords") + ":" + record.records;
					dis = "<div title='"+succeedTitle+"' ><font>"+succeedShow+"</font></div>";
				} else if (value == "3") {
					dis = $i18n("ccay.common.message.failed");
					var msg = record.fileName;
					if (msg != null) {
						return setShowError(msg, dis);
					}
				} else if (value == "4") {
					dis = $i18n("ccay.common.message.syncFailed");
					dis = "<font color=\"red\">"+dis+"</font>";
				}
				return dis;
			};

			setShowError = function(msg, dis) {
				msg = msg.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&acute;').replace(/"/g, '&quot;').replace(/(^\s*)|(\s*$)/g, "").replace(/\n/g, "");
				//return "<div title='" + $i18n("ccay.integration.label.processError") + "' ><a style='cursor:pointer' onclick=\"Ccay.UI.showMessage('" + msg + "','error')\"><font color=\"red\" style='text-decoration: underline'>" + dis + "</font></a><a class='ccay-icon warning' onclick=\"Ccay.UI.showMessage('" + msg + "','error')\"></a></div>";
				return "<div title='" + $i18n("ccay.integration.label.processError") + "' ><a style='cursor:pointer' onclick=\"Ccay.UI.showMessage('" + msg + "','error')\">" + dis + "</a><a class='ccay-icon warning' onclick=\"Ccay.UI.showMessage('" + msg + "','error')\"></a></div>";
			};
			tmpNamedownLoadRenderer = function(record) {
				var url = "";
				if(record.downloadUrl != null && record.downloadUrl != ""){
					url = ("<a href='{0}' title='{1}' class='link-special'>{2}</a>").formatValue(record.downloadUrl, $i18n("ccay.edm.label.downloadFile"),record.tmpName);
				}else {
					if (record.guid != null && record.exportFlag == 2) {
						url = ("<a href='servlet/iexcelexport?reportName={0}&guid={1}' title='${downloadFile}' class='link-special'>${fileName}</a>").formatURI(record.tmpName, record.guid).formatByMap({downloadFile:$i18n("ccay.edm.label.downloadFile"),fileName:record.fileName});
					} else if (record.guid == null && record.exportFlag == 2 && record.fileName != null) {
					 	if(record.currentContext){
					 		url = "<a href='{3}/servlet/download?dlType=Excel&excelId={0}&execFlag=EXP' class='link-special' title='{1}' >{2}</a>".formatValue(record.taskId,$i18n("ccay.edm.label.downloadFile"),record.tmpName,record.currentContext);
					 	}else{
					 		url = "<a href='servlet/download?dlType=Excel&excelId={0}&execFlag=EXP' class='link-special' title='{1}' >{2}</a>".formatValue(record.taskId,$i18n("ccay.edm.label.downloadFile"),record.tmpName);
					 	}
					}
				}
				return url;
			};

		});
